<? ini_set('memory_limit','1000M');?>
<style>
body { margin-top:25; font-size:12px;}
		.b_line { border-bottom:1px #AAAAAA solid; height:25px; font-size:14px}
		.border_t{border-top:1px inset #EEE;}
		.border_b{border-bottom:1px inset #EEE;}
		.border_l{border-left:1px inset #EEE;}
		.border_r{border-right:1px inset #EEE;}
		.xx:hover {cursor:pointer; background:#99FF99;}
		.xy:hover {cursor:pointer; background:#F30;}
		.box{border:1px solid #003}
		.box_t{border-top:1px solid #003;}
		.box_lbr{border:1px solid #003; border-top:none}
		.box_ltr{border:1px solid #003; border-bottom:none}
		.box_l{border-left:1px solid #003;}
		.box_r{border-right:1px solid #003;}
		.box_lb{border-left:1px solid #003;border-bottom:1px solid #003;}
		.box_rb{border-right:1px solid #003;border-bottom:1px solid #003;}
		.list_genap{cursor:pointer; background-color:#6699FF;}
		.list_ganjil{cursor:pointer; background-color:#9966FF;}
		.list_closed{cursor:pointer; background-color:#FF99FF;}
</style>
<table style='border-collapse:collapse' width='90%'>
	<tr align='center'><td colspan='3'><h2><?=$coy;?></h2><?=$add;?></td></tr>
	<tr align='center'><td colspan='3'><h1>NERACA</h1></td></tr>
	<tr align=''><td colspan='3'><b>Period :<?=$from_tgl;?></b><hr></td></tr>
	<!--aktiva section-->
	<tr><td colspan='3'><font style="font-size:large">AKTIVA</font></td></tr>	
	<?
		switch($lvl)
		{
			case '2':$ln=5;break;
			case '3':$ln=9;break;
			case '4':$ln=13;break;
		}
	 $aktivane=0;$tot_ak=0;
	 foreach($lst as $r){
		 $t_aktiva=($lvl!='2')?'0':$this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,5)='".$r->ckode."' group by left(ckode,5)");
		 ?>
		<tr>
			<td width='50%'><font color="#FFFFFF"><?=str_repeat("x",(strlen($r->ckode)-1));?></font><?=$r->susunan;?></td>
			<td width='15%' align='right'><?=number_format($t_aktiva,0);?></td>
			<td width='15%' align='right'></td>
		</tr>
		<?
		$aktv=0;
		$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
		$this->main_model->where(array('igrup'=>'0','levele <='=>$lvl,'levele >'=>'2'));
		$this->main_model->where_like('ckode',$r->ckode,'after');
		$datax=$this->main_model->generate_list('v_neraca',$ordby);
		foreach($datax as $d){
		$aktv	  =$this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,".$ln.")='".$d->ckode."' group by left(ckode,".$ln.")");
		$t_aktiva +=$this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,".$ln.")='".$d->ckode."' group by left(ckode,".$ln.")");
		$aktivane +=$t_aktiva;
		?>
		<!--aktiva lancar-->
		<tr>
			<td width='50%'><font color="#FFFFFF"><?=str_repeat("x",(strlen($d->ckode)-1));?></font><?=$d->susunan;?></td>
			<td width='15%' align='right'><?=number_format(($aktv),0);?></td>
			<td width='15%' align='right'></td>
		</tr>
		<? }?>
		<tr>
			<td width='50%' align='right'>Jumlah Aktiva <?= (substr($r->ckode,0,5)=='1.001')?"Lancar":"Tetap";?>
			<font color="#FFFFFF"><?=str_repeat("x",20);?></font></td>
			<td width='15%' align='right' class='box_t'></td>
			<td width='15%' align='right'><?=number_format($t_aktiva,0);?></td>
		</tr>
	<? }?>
		<tr>
			<td width='50%' align='right'>Jumlah Aktiva<font color="#FFFFFF"><?=str_repeat("x",20);?></font></td>
			<td width='15%' align='right' ></td>
			<td width='15%' align='right'class='box_t'><?=number_format($this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,1)='1' group by left(ckode,1)"),0);?></td>
		</tr>
		
	<!--Pasiva section-->
	<tr><td colspan='3'>&nbsp;</td></tr>	
	<tr><td colspan='3'><font style="font-size:large">PASIVA</font></td></tr>	
	<?
	  $sbtkwj=0; $pasivax=0;
	  foreach($lst2 as $r2){
	  $sbtkwj=($lvl!='2')?0:$this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,1)='".$r2->ckode."' group by left(ckode,1)");?>
		<tr>
			<td width='50%'><font color="#FFFFFF"><?=str_repeat("x",(strlen($r2->ckode)+4));?></font><?=$r2->susunan;?></td>
			<td width='15%' align='right'><?=($lvl!='2')?'0':number_format($this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,1)='".$r2->ckode."' group by left(ckode,1)"),0);?></td>
			<td width='15%' align='right'></td>
		</tr>
		<?
		$kwjb=0;
		$ordby=empty($_POST['ordby'])?'ckode':$_POST['ordby'];
		$this->main_model->where_like('ckode',$r2->ckode,'after');
		$this->main_model->where(array('igrup'=>'1','levele <='=>$lvl,'levele >='=>'2'));
		$dataxx=$this->main_model->generate_list('v_neraca',$ordby);
		foreach($dataxx as $d2){
		$kwjb=$this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,".($ln-4).")='".$d2->ckode."' group by left(ckode,".($ln-4).")");
		$sbtkwj +=$this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,".($ln-4).")='".$d2->ckode."' group by left(ckode,".($ln-4).")");
		$pasivax=($pasivax+$kwjb);
		?>

		<!--kewajiban-->
		<tr>
			<td width='50%'><font color="#FFFFFF"><?=str_repeat("x",(strlen($d2->ckode)+4));?></font><?=$d2->susunan;?></td>
			<td width='15%' align='right'><?=number_format((int)$kwjb,0);?></td>
			<td width='15%' align='right'><? $kode=$d2->ckode; $lvel=$d2->levele;?></td>
		</tr>
		<? }
		if(substr($kode,0,5)=='2.001')
		{
		?>
		<tr>
			<td width='50%' align='right'>Jumlah Kewajiban<font color="#FFFFFF"><?=str_repeat("x",20);?></font></td>
			<td width='15%' align='right' class='box_t'></td>
			<td width='15%' align='right'><?=number_format($sbtkwj,0);?></td>
		</tr>
		<? 
		}else if(substr($kode,0,5)=='3.004')
		{
		$rb=$this->main_model->rdb('jurnal','(sum(debet)-sum(kredit)) as jml',"where left(koderek,1) in ('4','5','6')");
		?>
		<tr>
			<td width='50%' align=''><font color="#FFFFFF"><?=str_repeat("x",15);?></font>Laba / Rugi berjalan</td>
			<td width='15%' align='right'><?=number_format((int)$rb,0);?></td>
			<td width='15%' align='right'></td>
		</tr>
		<tr>
			<td width='50%' align='right'>Jumlah Modal<font color="#FFFFFF"><?=str_repeat("x",20);?></font></td>
			<td width='15%' align='right' class='box_t'></td>
			<td width='15%' align='right'><?=number_format(($sbtkwj+$rb),0);?></td>
		</tr>
		<? 
		}
	}
	$pasiva=$this->main_model->rdb('v_neraca','sum(jml) as jml',"where left(ckode,1) in('2','3')/* n group by left(ckode,1)*/")
	?>
		<tr>
			<td width='50%' align='right'>Jumlah Pasiva<font color="#FFFFFF"><?=str_repeat("x",20);?></font></td>
			<td width='15%' align='right' ></td>
			<td width='15%' align='right'class='box_t'><?=number_format(($pasiva+$rb),0);?></td>
		</tr>
		<tr><td colspan='3'>&nbsp;</td></tr>
		<tr><td colspan='3'>&nbsp;</td></tr>
		<tr><td colspan='3'>&nbsp;</td></tr>
		<!-----Footer tanda tangan ---->
			<? $kt=explode("-",$kota);?>
			<tr><td></td><td colspan='2' align='center'><?=$kt[0].", ". date('d F Y');?></td></tr>
			<tr><td height="50px">&nbsp;</td><td colspan='2' align='center' valign='top'><?='Keuangan,';?></td></tr>
			<tr><td></td><td colspan='2' align='center'><?=$keua;?></td></tr>
</table>	
